package com.chenqi.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @description: 统一接口返回
 * @program: ardaicommunity
 * @author: ChenQi
 * @create: 2021-03-2021/3/7-08-36
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonData {
    private Integer code;
    private Object data;
    private String msg;

    //成功仅仅返回状态码
    public static JsonData BuildSuccess(){
        return new JsonData(0, null, null);
    }
    //成功返回状态码和数据
    public static JsonData BuildSuccess(Object data){
        return new JsonData(0, data, null);
    }
    //成功返回状态码和数据
    public static JsonData BuildSuccess(String msg){
        return new JsonData(0, null, msg);
    }
    //成功返回状态码数据和信息
    public static JsonData BuildSuccess(Object data,String msg){
        return new JsonData(0, data, msg);
    }
    //失败返回状态码和失败信息
    public static JsonData BuildError(String msg) {
        return new JsonData(-1, null, msg);
    }
    //返回指定错误状态码
    public static JsonData BuildError(Integer code,String msg){
        return new JsonData(code, null, msg);
    }
}
